import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BusiserviceProvider } from '../../providers/busiservice/busiservice';
import { UiserviceProvider } from '../../providers/uiservice/uiservice';

/**
 * Generated class for the QzzaddPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-qzzadd',
  templateUrl: 'qzzadd.html',
})
export class QzzaddPage {
  name: any;
  phonenum: any;
  age: any;
  sex: any;
  email: any;
  zzjy: any;//工作经历
  jnms: any;//技能描述
  grjs: any;//个人简述
  userid: any;
  qzzid:any;
  constructor(public navCtrl: NavController, public navParams: NavParams, public busi: BusiserviceProvider, private uiservice: UiserviceProvider) {
    this.userid = localStorage.getItem("userid");
    this.getqzzinfo();

  }

  getqzzinfo(){
    this.busi.getQzzinfo(this.userid).subscribe(
      data=>{
        if(data._success){
          this.name =data.result.name;
          this.phonenum =data.result.phonenum;
          this.age = data.result.age;
          this.sex=data.result.sex;
          this.email = data.result.email;
          this.zzjy = data.result.zzjy;
          this.jnms= data.result.jnms;
          this.grjs =data.result.grjs;
          this.qzzid = data.result.qzzid;
        }else{
          this.uiservice.showAlert(data._message);
        }
      },
      error=>{
        this.uiservice.showAlert("Net Error");
      }
    );
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad QzzaddPage');
  }
  saveqzz() {
    if (this.name == null || this.name == '') {
      alert("User Name is Empty！");
      return;
    }

    if (this.phonenum == null || this.phonenum == '') {
      alert("Phone is Empty！");
      return;
    }
    if (this.age == null || this.age == '') {
      alert("Age is Empty！");
      return;
    }
    if (this.sex == null || this.sex == '') {
      alert("Sex is Empty！");
      return;
    }
    if (this.email == null || this.email == '') {
      alert("Email is Empty！");
      return;
    }
    if (this.zzjy == null || this.zzjy == '') {
      alert("Work Experience is Empty！");
      return;
    }
    if (this.jnms == null || this.jnms == '') {
      alert("Skill Description is Empty！");
      return;
    }
    if (this.grjs == null || this.grjs == '') {
      alert("Personal Description is Empty！");
      return;
    }
    let qzz: Qzz = new Qzz();
    qzz.name = this.name;
    qzz.phonenum = this.phonenum;
    qzz.age = this.age;
    qzz.sex = this.sex;
    qzz.email = this.email;
    qzz.zzjy = this.zzjy;
    qzz.jnms = this.jnms;
    qzz.grjs = this.grjs;
    qzz.userid = this.userid;
    qzz.qzzid=this.qzzid;
    this.uiservice.showLoading();
    this.busi.addqzz(qzz).subscribe(
      data => {
        this.uiservice.hideLoading();
        if (data._success) {
          this.uiservice.showToast("Save Successfully!");
        } else {
          this.uiservice.showAlert(data._message);
        }
      },
      error => {
        this.uiservice.hideLoading();
        this.uiservice.showAlert("Net Error");
      }
    );

  }

}
class Qzz {
  name: any;
  phonenum: any;
  age: any;
  sex: any;
  email: any;
  zzjy: any;
  jnms: any;
  grjs: any;
  userid: any;
  qzzid:any;
}
